	<?php

	echo "<h2 id='contentTitle'>".$pageTitle."</h2>";
	echo $this->renderElement('message');
	echo '<div>Discuta e interaja com membros da sua entidade e de outras entidades.<br><br> </div>';

	if ($othAuth->hasPermission('forums/add/')) {
		$addButton = "<span class=\"buttonAdd\">Nova discussão</span>";
		echo html_entity_decode($html->link($addButton, '/forums/add/',array('class'=>'button')));
	}

	if (isset($forums) && is_array($forums) && (!empty($forums))) {
		echo "<table >";

		echo "<thead>";
		echo "<div></div>";
		echo "<tr class='tableHeader'>";
		echo "<th class='tableHeaderBegin'>Título</th>";
		echo "<th class='tableHeaderMiddle'>Data de criação</th>";
		echo "<th class='tableHeaderMiddle'>Autor</th>";
		echo "<th class='tableHeaderMiddle'>Pública</th>";
		if ($othAuth->hasPermission('forums/delete/')) {
			echo "<th class='tableHeaderEnd'>Excluir</th>";
		}
		echo "</tr>";
		echo "</thead>";
		echo "<tfoot>";
		echo "<tr class='tableFooter'>
		<td colspan='5'></td>
		</tr>";
		echo "</tfoot>";

		$i=0;
		foreach ($forums as $forum) {
			if (($i++ % 2) == 1) $zebrado = " class='oddTr' ";
			else $zebrado = "";
			echo "<tr ".$zebrado.">";
			echo "<td>".$html->link($forum['Forum']['title'],'/forums/view/'.$forum['Forum']['id'])."</td>";

			echo "<td class='tdCenter'>".date("d/m/Y",strtotime($forum['Forum']['created']))."</td>";

			echo "<td>".$forum['Createdby']['name']."</td>";
			
			$public = ($forum['Forum']['public'] == 1)?'Sim':'Não'; 
			echo "<td>".$public."</td>";
			
			if ($othAuth->hasPermission('forums/delete/')) {
				echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('filedel.png',array('class'=>'icon')), '/forums/delete/'.$forum['Forum']['id'], array(), 'Confirma a exclusão deste item?'))."</td>";
			}
			echo "</tr>";
		}
		echo "</table> <br>";
	} else {
		echo "<p>Não há nenhuma discussão iniciada.</p>";
	}
